<ui:composition xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets" template="/home.xhtml">
	<ui:define name="corpo">
		<h:form prependId="false">
			<p:panel header="Administrar Pacientes" style="background: #dbfbda;font-size:15px;min-height:700px;margin-top:10px;float:left;width:99%">
				<h:panelGroup style="float: left;width:250px;" layout="block">
					<ui:include src="menu.xhtml" />
				</h:panelGroup>
				<h:panelGroup layout="block" style="float:left">
				    	<p:dataTable var="paciente" value="#{manterAdministradorBean.administradorForm.pacientes}" id="table_paciente" paginator="true" rows="15"  
				                 paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" 
				                 paginatorPosition="bottom" style="width:700px">  
					  
				            <f:facet name="header">  
				                <h:outputText value="Pacientes Cadastrados" />
				            </f:facet>  
					        <p:column>  
					            <f:facet name="header">  
					                <h:outputText value="Paciente" />  
					            </f:facet>  
					            <h:outputText value="#{paciente.nome}" />  
					        </p:column>  

					        <p:column>  
					            <f:facet name="header">  
					                <h:outputText value="Email" />  
					            </f:facet>  
					            <h:outputText value="#{paciente.email}" />  
					        </p:column>  

					        <p:column style="text-align: center">  
					            <f:facet name="header">  
					                <h:outputText value="Excluir" />  
					            </f:facet>  
					            <p:commandButton image="ui-icon ui-icon-trash" oncomplete="excluir.show()">
					            	<f:setPropertyActionListener target="#{manterPacienteADMBean.paciente}" value="#{paciente}" />
					            </p:commandButton>  
					        </p:column>  
	
					        <p:column style="text-align: center">  
					            <f:facet name="header">  
					                <h:outputText value="Editar" />  
					            </f:facet>  
					            <p:commandButton image="ui-icon ui-icon-transferthick-e-w" oncomplete="editar.show()" update="pnl_edit,pnlTelefones">
					            	<f:setPropertyActionListener target="#{manterPacienteADMBean.paciente}" value="#{paciente}" />					            	
					            </p:commandButton>
					        </p:column>  
					  
					  		<f:facet name="footer">
				                <p:commandButton value="Cadastrar" image="ui-icon ui-icon-circle-plus" style="position: relative; right: 290px;" oncomplete="cadastrar.show()" action="#{manterPacienteADMBean.limparCampo}" update="pnl_cadastro" />
				            </f:facet>
					    </p:dataTable>
				</h:panelGroup>
			 
			</p:panel>
			
		</h:form>
		
		<ui:include src="modal_excluir_admin.xhtml">
			<ui:param name="bean" value="#{manterPacienteADMBean}" />
			<ui:param name="metodo" value="excluir" />
			<ui:param name="idTabela" value="table_paciente" />
		</ui:include>
		
		<p:dialog header="Editar" widgetVar="editar" resizable="false" modal="true" width="650" showEffect="clip" hideEffect="fold">
			<h:form prependId="false">

				<h:panelGrid columns="4" cellpadding="2" cellspacing="0" id="pnl_edit">
			
					<h:outputLabel value="#{msg['display.label.paciente.nome']}" style="font-weight:bold" for="nome" styleClass="fmt_label_form_cadastro" />
					<p:inputText value="#{manterPacienteADMBean.paciente.nome}" size="30" maxlength="100" required="true" label="nome" id="nome" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputLabel value="#{msg['display.label.paciente.cpf']}" style="font-weight:bold" for="cpf" styleClass="fmt_label_form_cadastro" />
					<p:inputMask value="#{manterPacienteADMBean.paciente.cpf}" mask="999.999.999-99" size="14" maxlength="14" required="true" label="cpf" id="cpf" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro">
						<f:converter converterId="com.automed.cpfConverter"/>
						<f:validator validatorId="com.automed.cpfValidator"/>
					</p:inputMask>					
					
					<h:outputText />
					<h:message for="nome" id="msgNome" styleClass="msg_erro_required"/>
					<h:outputText />
					<h:message for="cpf" id="msgCPF" styleClass="msg_erro_required"/>
					
					<h:outputLabel value="#{msg['display.label.paciente.rg']}" style="font-weight:bold" for="rg" styleClass="fmt_label_form_cadastro" />
					<p:inputMask value="#{manterPacienteADMBean.paciente.rg}" mask="99.999.999-9" size="12" maxlength="12" required="true" label="rg" id="rg" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />	
					<h:outputLabel value="#{msg['display.label.paciente.login']}" style="font-weight:bold" for="login" styleClass="fmt_label_form_cadastro" />
					<p:inputText value="#{manterPacienteADMBean.paciente.login}" size="20" maxlength="50" required="true" label="login" id="login" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />									
					
					<h:outputText />
					<h:message for="rg" id="msgRG" styleClass="msg_erro_required"/>
					<h:outputText />
					<h:message for="login" id="msgLogin" styleClass="msg_erro_required"/>


					<h:outputLabel value="#{msg['display.label.paciente.email']}" style="font-weight:bold" for="email" styleClass="fmt_label_form_cadastro" />
					<p:inputText value="#{manterPacienteADMBean.paciente.email}" size="30" maxlength="50" required="true" label="email" id="email" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro">
						<f:validator validatorId="com.automed.emailValidator"/>
					</p:inputText>
					<h:outputLabel value="#{msg['display.label.paciente.matricula']}" style="font-weight:bold" for="matricula" styleClass="fmt_label_form_cadastro" />
					<p:inputMask value="#{manterPacienteADMBean.paciente.matricula}" mask="9999999999" size="10" maxlength="10" required="true" label="matricula" id="matricula" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro">
						<p:tooltip for="matricula" value="Por favor, digite a matrícula fornecida pelo seu convênio" showEvent="focus" hideEvent="blur"/>
					</p:inputMask>					
					
					<h:outputText />
					<h:message for="email" id="msgEmail" styleClass="msg_erro_required"/>					
					<h:outputText />
					<h:message for="matricula" id="msgMatricula" styleClass="msg_erro_required"/>
					

					<h:outputLabel value="#{msg['display.label.paciente.convenio']}" style="font-weight:bold" for="convenio" styleClass="fmt_label_form_cadastro" />
					<h:selectOneMenu value="#{manterPacienteADMBean.paciente.convenio}" id="convenio" style="font-size:12px">
						<f:selectItem itemLabel="" noSelectionOption="true" />
						<f:selectItems value="#{manterPacienteADMBean.pacienteForm.convenios}" var="entity" itemLabel="#{entity.convenio}" itemValue="#{entity}" />						
					</h:selectOneMenu>					
					<h:outputLabel value="#{msg['display.label.paciente.bairro']}" style="font-weight:bold" for="bairro" styleClass="fmt_label_form_cadastro" />
					<p:inputText value="#{manterPacienteADMBean.paciente.endereco.bairro}" required="true" size="25" maxlength="100" label="bairro" id="bairro" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					
					<h:outputText />
					<h:message for="convenio" id="msgConvenio" />					
					<h:outputText />
					<h:message for="bairro" id="msgBairro" styleClass="msg_erro_required"/>

					<h:outputLabel value="#{msg['display.label.paciente.cep']}" style="font-weight:bold" for="cep" styleClass="fmt_label_form_cadastro" />
					<p:inputMask value="#{manterPacienteADMBean.paciente.endereco.cep}" mask="99999-999" size="9" maxlength="8" required="true" label="cep" id="cep" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputLabel value="#{msg['display.label.paciente.complemento']}" style="font-weight:bold" for="complemento" styleClass="fmt_label_form_cadastro" />
					<p:inputText value="#{manterPacienteADMBean.paciente.endereco.complemento}" required="true" size="6" maxlength="50" label="complemento" id="complemento" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />					
					
					<h:outputText />
					<h:message for="cep" id="msgCEP" styleClass="msg_erro_required"/>					
					<h:outputText />
					<h:message for="complemento" id="msgComplemento" styleClass="msg_erro_required"/>

					<h:outputLabel value="#{msg['display.label.paciente.logradouro']}" style="font-weight:bold" for="logradouro" styleClass="fmt_label_form_cadastro" />
					<p:inputText value="#{manterPacienteADMBean.paciente.endereco.endereco}" required="true" size="36" maxlength="100" label="logradouro" id="logradouro" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputLabel value="#{msg['display.label.paciente.numero']}" style="font-weight:bold" for="numero" styleClass="fmt_label_form_cadastro" />
					<p:inputMask value="#{manterPacienteADMBean.paciente.endereco.numero}" required="true" mask="?999999" size="6" label="numero" id="numero" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />					
					
					<h:outputText />
					<h:message for="logradouro" id="msgLogradouro" styleClass="msg_erro_required"/>					
					<h:outputText />
					<h:message for="numero" id="msgNumero" styleClass="msg_erro_required" />
				
					<h:outputLabel value="#{msg['display.label.paciente.cidade']}" style="font-weight:bold" for="cidade" styleClass="fmt_label_form_cadastro" />
					<h:selectOneMenu value="#{manterPacienteADMBean.paciente.endereco.cidade}" id="cidade" style="font-size:12px">
						<f:selectItem itemLabel="" noSelectionOption="true" />
						<f:selectItems value="#{manterPacienteADMBean.pacienteForm.cidades}" var="entity" itemLabel="#{entity.cidade}" itemValue="#{entity}" />
					</h:selectOneMenu>					
					<h:outputText />
					<h:message for="cidade" id="msgCidade" styleClass="msg_erro_required"/>
					
		
				</h:panelGrid>
				
				<h:panelGroup layout="block" style="margin-top:5px" id="pnlTelefones">
					<ui:repeat var="entity" value="#{manterPacienteADMBean.paciente.telefones}">
						<h:panelGroup layout="block" style="float:left;width:75px;margin-top:4px">
							<h:outputLabel style="font-weight:bold" value="#{entity.tipoTelefone.tipo eq 'Celular' ? 'Celular: ' : (entity.tipoTelefone.tipo eq 'Comercial' ? 'Comercial: ' : (entity.tipoTelefone.tipo eq 'Residencial' ? 'Residencial: ' : ''))}" for="tel1" styleClass="fmt_label_form_cadastro" />
						</h:panelGroup>
						<h:panelGroup layout="block" style="float:left;">
							<p:inputMask value="#{entity.telefone}" mask="(99)9999-9999" required="#{entity.tipoTelefone.tipo eq 'Residencial'}" label="#{entity.tipoTelefone.tipo eq 'Celular' ? 'Celular' : (entity.tipoTelefone.tipo eq 'Comercial' ? 'Comercial' : (entity.tipoTelefone.tipo eq 'Residencial' ? 'Residencial' : ''))}" id="tel1" size="13" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
						</h:panelGroup>												
						<h:message for="tel1" id="msgTEL1" style="float:left;margin-top:4px" styleClass="msg_erro_required"/>
						
					</ui:repeat>
				</h:panelGroup>
				
				<h:panelGroup style="margin-top: 40px;text-align:center;" layout="block">
					<p:commandButton value="#{msg['display.view.adm.salvar']}" action="#{manterPacienteADMBean.editar}" oncomplete="validaEdicao();" update="pnl_edit,table_paciente,func_javascript,pnlTelefones"/>
					<p:commandButton value="#{msg['display.view.adm.cancelar']}" oncomplete="editar.hide()"/>
				</h:panelGroup>
				

			</h:form>
	    </p:dialog>
	    
		<p:dialog header="Cadastrar" widgetVar="cadastrar" resizable="false" modal="true" width="600" showEffect="clip" hideEffect="fold">
			<h:form prependId="false">
				
				<h:panelGrid columns="2" cellpadding="5" cellspacing="0" id="pnl_cadastro">
			
					<h:outputLabel value="#{msg['display.label.paciente.nome']}" for="nomeCad" styleClass="fmt_label_form_cadastro" />
					<p:inputText value="#{manterPacienteADMBean.paciente.nome}" size="50" maxlength="100" required="true" label="nome" id="nomeCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="nomeCad" id="msgNomeCad" styleClass="msg_erro_required"/>
					
					<h:outputLabel value="#{msg['display.label.paciente.cpf']}" for="cpfCad" styleClass="fmt_label_form_cadastro" />
					<p:inputMask value="#{manterPacienteADMBean.paciente.cpf}" mask="999.999.999-99" size="14" maxlength="14" required="true" label="cpf" id="cpfCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro">
						<f:converter converterId="com.automed.cpfConverter"/>
						<f:validator validatorId="com.automed.cpfValidator"/>
						<f:validator validatorId="com.automed.cpfValidatorExistente"/>
					</p:inputMask>
					<h:outputText />
					<h:message for="cpfCad" id="msgCPFCad" styleClass="msg_erro_required"/>
					
					<h:outputLabel value="#{msg['display.label.paciente.rg']}" for="rgCad" styleClass="fmt_label_form_cadastro" />
					<p:inputMask value="#{manterPacienteADMBean.paciente.rg}" mask="99.999.999-9" size="12" maxlength="12" required="true" label="rg" id="rgCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="rgCad" id="msgRGCad" styleClass="msg_erro_required"/>

					<h:outputLabel value="#{msg['display.label.paciente.login']}" for="loginCad" styleClass="fmt_label_form_cadastro" />
					<p:inputText value="#{manterPacienteADMBean.paciente.login}" size="10" maxlength="50" required="true" label="login" id="loginCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="loginCad" id="msgLoginCad" styleClass="msg_erro_required"/>

					<h:outputLabel value="#{msg['display.label.paciente.senha']}" for="senhaCad" styleClass="fmt_label_form_cadastro" />
					<p:password value="#{manterPacienteADMBean.paciente.senha}" promptLabel="Por favor, digite sua senha" weakLabel="Fraca" goodLabel="Média" strongLabel="Forte" size="10" maxlength="20" required="true" style="border: solid 1px #5FA03F;background-color: #FFF;" label="senha" id="senhaCad" password="true" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="senhaCad" id="msgSenhaCad" styleClass="msg_erro_required"/>

					<h:outputLabel value="#{msg['display.label.paciente.email']}" for="emailCad" styleClass="fmt_label_form_cadastro" />
					<p:inputText value="#{manterPacienteADMBean.paciente.email}" size="50" maxlength="50" required="true" label="email" id="emailCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro">
						<f:validator validatorId="com.automed.emailValidator"/>
					</p:inputText>
					<h:outputText />
					<h:message for="emailCad" id="msgEmailCad" styleClass="msg_erro_required"/>

					<h:outputLabel value="#{msg['display.label.paciente.matricula']}" for="matriculaCad" styleClass="fmt_label_form_cadastro" />
					<p:inputMask value="#{manterPacienteADMBean.paciente.matricula}" mask="9999999999" size="10" maxlength="10" required="true" label="matricula" id="matriculaCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:panelGroup>
						<h:message for="matriculaCad" id="msgMatriculaCad" styleClass="msg_erro_required"/>
						<p:tooltip for="matriculaCad" value="Por favor, digite a matrícula fornecida pelo seu convênio" showEvent="focus" hideEvent="blur"/>
					</h:panelGroup>

					<h:outputLabel value="#{msg['display.label.paciente.convenio']}" for="convenioCad" styleClass="fmt_label_form_cadastro" />
					<h:selectOneMenu value="#{manterPacienteADMBean.paciente.convenio}" id="convenioCad" style="font-size:12px">
						<f:selectItem itemLabel="" noSelectionOption="true" />
						<f:selectItems value="#{manterPacienteADMBean.pacienteForm.convenios}" var="entity" itemLabel="#{entity.convenio}" itemValue="#{entity}" />
					</h:selectOneMenu>
					<h:outputText />
					<h:panelGroup>
						<h:message for="convenioCad" id="msgConvenioCad" />
						<p:tooltip for="convenioCad" value="Por favor, escolha o convênio equivalente a sua matrícula" showEvent="focus" hideEvent="blur"/>
					</h:panelGroup>
				
					<h:outputLabel value="#{msg['display.label.paciente.tel1']}" for="tel1Cad" styleClass="fmt_label_form_cadastro" />
					<p:inputMask value="#{manterPacienteADMBean.residencial.telefone}" mask="(99)9999-9999"  required="true" label="Residencial" id="tel1Cad" size="13" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="tel1Cad" id="msgTEL1Cad" styleClass="msg_erro_required"/>

					<h:outputLabel value="#{msg['display.label.paciente.tel2']}" for="tel2Cad" styleClass="fmt_label_form_cadastro" />
					<p:inputMask value="#{manterPacienteADMBean.celular.telefone}" mask="(99)9999-9999" label="tel2" id="tel2Cad" size="13" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="tel2Cad" id="msgTEL2Cad" />

					<h:outputLabel value="#{msg['display.label.paciente.tel3']}" for="tel3Cad" styleClass="fmt_label_form_cadastro" />
					<p:inputMask value="#{manterPacienteADMBean.comercial.telefone}" mask="(99)9999-9999" label="tel3" id="tel3Cad" size="13" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="tel3Cad" id="msgTEL3Cad" />
					
					<h:outputLabel value="#{msg['display.label.paciente.bairro']}" for="bairroCad" styleClass="fmt_label_form_cadastro" />
					<p:inputText value="#{manterPacienteADMBean.paciente.endereco.bairro}" required="true" size="50" maxlength="100" label="bairro" id="bairroCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="bairroCad" id="msgBairroCad" styleClass="msg_erro_required"/>

					<h:outputLabel value="#{msg['display.label.paciente.cep']}" for="cepCad" styleClass="fmt_label_form_cadastro" />
					<p:inputMask value="#{manterPacienteADMBean.paciente.endereco.cep}" mask="99999-999" size="9" maxlength="8" required="true" label="cep" id="cepCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="cepCad" id="msgCEPCad" styleClass="msg_erro_required"/>

					<h:outputLabel value="#{msg['display.label.paciente.complemento']}" for="complementoCad" styleClass="fmt_label_form_cadastro" />
					<p:inputText value="#{manterPacienteADMBean.paciente.endereco.complemento}" required="true" size="50" maxlength="50" label="complemento" id="complementoCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="complementoCad" id="msgComplementoCad" styleClass="msg_erro_required"/>

					<h:outputLabel value="#{msg['display.label.paciente.logradouro']}" for="logradouroCad" styleClass="fmt_label_form_cadastro" />
					<p:inputText value="#{manterPacienteADMBean.paciente.endereco.endereco}" required="true" size="50" maxlength="100" label="logradouro" id="logradouroCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="logradouroCad" id="msgLogradouroCad" styleClass="msg_erro_required"/>

					<h:outputLabel value="#{msg['display.label.paciente.numero']}" for="numeroCad" styleClass="fmt_label_form_cadastro" />
					<p:inputMask value="#{manterPacienteADMBean.paciente.endereco.numero}" required="true" mask="?999999" size="6" label="numero" id="numeroCad" style="border: solid 1px #5FA03F;background-color: #FFF;" styleClass="fmt_input_form_cadastro" />
					<h:outputText />
					<h:message for="numeroCad" id="msgNumeroCad" styleClass="msg_erro_required" />
				
					<h:outputLabel value="#{msg['display.label.paciente.cidade']}" for="cidadeCad" styleClass="fmt_label_form_cadastro" />
					<h:selectOneMenu value="#{manterPacienteADMBean.paciente.endereco.cidade}" id="cidadeCad" style="font-size:12px">
						<f:selectItem itemLabel="" noSelectionOption="true" />
						<f:selectItems value="#{manterPacienteADMBean.pacienteForm.cidades}" var="entity" itemLabel="#{entity.cidade}" itemValue="#{entity}" />
					</h:selectOneMenu>
					<h:outputText />
					<h:message for="cidadeCad" id="msgCidadeCad" styleClass="msg_erro_required"/>
						
				</h:panelGrid>
				<h:panelGroup style="padding-top: 20px;padding-bottom:10px;text-align:center" layout="block">
					<p:commandButton value="#{msg['display.view.adm.salvar']}" action="#{manterPacienteADMBean.cadastrar}" oncomplete="validaCadastro();" update="pnl_cadastro,table_paciente,func_javascript"/>
					<p:commandButton value="#{msg['display.view.adm.cancelar']}" onclick="cadastrar.hide()"/>
				</h:panelGroup>
				
				<p:outputPanel id="func_javascript">
					<script type="text/javascript">
	
						function validaCadastro(){
							if(#{!empty requestScope.cadastrado}){
								cadastrar.hide();
							}
						}
										
						function validaEdicao(){
							if(#{!empty requestScope.editado}){
								editar.hide();
							}
						}						
								
					</script>
				</p:outputPanel>
				
			</h:form>
			
	    </p:dialog>
		
		
	</ui:define>
</ui:composition>